package com.example.demo.controller;

import com.example.demo.core.StandardResult;
import com.example.demo.domain.CommodityEntity;
import com.example.demo.mapper.CommodityMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "CommodityController",description = "商品模块接口description",produces ="商品模块接口produces" )
@RestController
@RequestMapping("/commodity")
public class CommodityController extends BaseController{

    @Autowired
    CommodityMapper commodityMapper;

    @ApiOperation(value = "根据商品名称获取商品信息")
    @RequestMapping(value = "/get/{name}",method = RequestMethod.GET)
    public StandardResult getCommodityByName(@PathVariable String name) {
        CommodityEntity commodityEntity = commodityMapper.findByName(name);

        return success(commodityEntity);
    }

    @ApiOperation(value = "根据商品名称获取商品信息")
    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public List<CommodityEntity> getAll() {
        List<CommodityEntity> commodityEntities = commodityMapper.queryAll();

        return commodityEntities;
    }

    @ApiOperation(value = "保存商品信息")
    @RequestMapping(value = "/save/{id}/{name}/{price}",method = RequestMethod.GET)
    public void saveCommodity(@PathVariable long id, @PathVariable String name, @PathVariable float price) {
        /*CommodityEntity commodityEntity=new CommodityEntity();
        commodityEntity.setId(id);
        commodityEntity.setCommodityName(name);
        commodityEntity.setPrice(price);
        */

        commodityMapper.insert(id, name, price);
    }
}
